package Day13;


import java.io.*;

/**
 * @Author kalista
 * @Description
 * @Date 2020/11/19  16:04
 **/
public class TestObject {
    public static void main(String[] args) throws IOException {

        // 对象流
        // 对象输出流

        // 序列化
//        Dog dog = new Dog(1, "Tom", 2);
//        ObjectOutputStream objectOutputStream = null;
//        FileOutputStream fileOutputStream = null;
//
//        try {
//
//            fileOutputStream = new FileOutputStream("f:\\dog.info");
//            objectOutputStream = new ObjectOutputStream(fileOutputStream);
//            objectOutputStream.writeObject(dog);
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }finally {
//            objectOutputStream.close();
//            fileOutputStream.close();
//        }

        //反序列化

        FileInputStream fileInputStream = null;
        ObjectInputStream objectInputStream = null;
        try {
            fileInputStream = new FileInputStream("f:\\\\dog.info");

            objectInputStream  = new ObjectInputStream(fileInputStream);

            Dog o = (Dog) objectInputStream.readObject();
            System.out.println(o);


        } catch (IOException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
        }

    }
}
